package com.tyjt.common.mqtt.config;

import org.eclipse.paho.client.mqttv3.MqttMessage;

import java.lang.reflect.Method;

public class MethodHandler implements DataHandler {

    private final Object target;

    private final Method method;

    public MethodHandler(Object target, Method method) {
        this.target = target;
        this.method = method;
    }

    @Override
    public void handle(String topic ,MqttMessage message) throws Exception {
        method.invoke(target, topic,message);
    }


    @Override
    public String toString() {
        return super.toString() + "[" + target.getClass() + "#" + method.getName() + "]";
    }
}
